﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.quest.Display.QuestManager {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.util.*;
    import com.greensock.*;
    import Display.*;
    import Modules.guide.*;
    import Display.hud.components.*;
    import Display.aswingui.*;
    import Display.hud.*;

    public class QuestManagerView extends Sprite {

        public static const QUEST_MANAGER_WIDTH:int = ((QuestManagerUI.NUM_COLUMNS * QuestManagerCell.CELL_WIDTH) + 20);
        public static const QUEST_MANAGER_HEIGHT:int = ((QuestManagerUI.NUM_ROWS * QuestManagerCell.CELL_HEIGHT) + 20);
        public static const QUEST_MANAGER_TOOLTIP_WIDTH:int = 200;
        public static const QUEST_MANAGER_TOOLTIP_HEIGHT:int = 180;
        public static const QUEST_MANAGER_ENABLED:String = "QuestManagerEnabled";
        public static const QUEST_MANAGER_DISABLED:String = "QuestManagerDisabled";

        public static var assetDict:Dictionary;

        protected var m_questManagerComponent:HUDQuestManagerComponent;
        protected var m_content:QuestManagerUI;
        protected var m_window:JWindow;
        protected var m_holder:Sprite;
        protected var m_comObject:Object;
        protected var m_shown:Boolean = false;
        protected var m_cursorId:int = 0;
        protected var m_assetsLoaded:Boolean = false;
        protected var m_showOnLoad:Boolean = false;

        public function QuestManagerView(){
            this.m_questManagerComponent = (Global.hud.getComponent(HUD.COMP_QUESTS) as HUDQuestManagerComponent);
            this.alpha = 0;
            this.loadAssets();
            this.m_content = new QuestManagerUI();
        }
        protected function loadAssets():void{
            Global.delayedAssets.get(DelayedAssetLoader.QUEST_ASSETS, this.makeAssets);
        }
        protected function makeAssets(_arg1:DisplayObject, _arg2:String):void{
            this.m_comObject = _arg1;
            this.setChrome();
        }
        protected function setChrome():void{
            QuestManagerView.assetDict = new Dictionary(true);
            QuestManagerView.assetDict["questManagerBG"] = this.m_comObject.questManagerBG;
            QuestManagerView.assetDict["questManagerCellBG"] = this.m_comObject.questManagerCellBG;
            QuestManagerView.assetDict["questManagerSlotBG"] = this.m_comObject.questManagerSlotBG;
            this.m_holder = new Sprite();
            this.addChild(this.m_holder);
            this.m_window = new JWindow(this.m_holder);
            this.m_window.setContentPane(this.m_content);
            ASwingHelper.prepare(this.m_window);
            this.m_window.show();
            this.m_content.init(this);
            this.m_cursorId = UI.setCursor(null);
            this.mouseEnabled = (this.mouseChildren = false);
            this.m_assetsLoaded = true;
            if (this.m_showOnLoad){
                this.show();
            };
        }
        public function get isShown():Boolean{
            return (this.m_shown);
        }
        public function show():void{
            if (!this.m_assetsLoaded){
                this.m_showOnLoad = true;
                return;
            };
            if (this.m_content.guideArrow){
                Global.guide.removeArrows();
                this.m_content.guideArrow = null;
            };
            this.showTween();
        }
        public function close():void{
            var dispObj:* = null;
            dispObj = this;
            this.hideTween(function ():void{
                if (dispObj.parent){
                    dispObj.parent.removeChild(dispObj);
                };
                dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
                onHide();
            });
            Global.player.saveQuestOrderSequence();
        }
        protected function showTween():void{
            this.mouseEnabled = (this.mouseChildren = false);
            this.visible = true;
            this.centerPopup();
            TweenLite.to(this, 0.5, {
                alpha:1,
                onComplete:this.onShow
            });
            this.showMask();
            dispatchEvent(new Event(QUEST_MANAGER_ENABLED));
            Sounds.play("dialogSpawn");
        }
        protected function onShow():void{
            this.m_cursorId = UI.setCursor(null);
            this.m_shown = true;
            if (this.m_content.fixLayout()){
            };
            this.mouseEnabled = (this.mouseChildren = true);
            Global.ui.mouseEnabled = (Global.ui.mouseChildren = true);
            UI.popupLock();
        }
        protected function hideTween(_arg1:Function):void{
            this.mouseEnabled = (this.mouseChildren = false);
            if (this.m_content == null){
                if (_arg1 != null){
                    _arg1();
                };
            } else {
                TweenLite.to(this, 0.5, {
                    alpha:0,
                    onComplete:_arg1
                });
            };
            dispatchEvent(new Event(QUEST_MANAGER_DISABLED));
            this.hideMask();
            Sounds.play("dialogClose");
        }
        protected function onHide():void{
            if (this.m_shown == true){
                this.m_shown = false;
                this.mouseEnabled = (this.mouseChildren = false);
            };
            UI.popupUnlock();
        }
        public function centerPopup():void{
            var _local1:Rectangle;
            if (parent){
                _local1 = Global.hud.getRect(parent);
                this.x = (_local1.x + 90);
                this.y = (_local1.y + 60);
            };
        }
        protected function showMask():void{
            Global.guide.displayMaskUI(GuideConstants.MASK_GAME_AND_BOTTOMBAR, 0.5);
        }
        protected function hideMask():void{
            Global.guide.removeMask();
        }
        public function get content():QuestManagerUI{
            return (this.m_content);
        }

    }
}//package Modules.quest.Display.QuestManager 
